package com.bupt.jack.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.codehaus.jettison.json.JSONArray;

import com.bupt.jack.model.GroupItem;
import com.bupt.jack.service.GroupItemService;

public class GroupItemAction extends BaseAction implements ServletRequestAware,ServletResponseAware {

	/**
	 * author: jack
	 * function: get items on group
	 */
	private static final long serialVersionUID = -161231514540082002L;

	private int pageSize = 10;
	
	private int pageNow ;
	
	private GroupItemService groupItemService;
	
	HttpServletRequest request;
	HttpServletResponse response;
	
	public String execute(){
	
		return null;
	
	}
	
	public void GetItemList(){

		List<GroupItem> itemList = this.groupItemService.findOnGroupItems(pageNow, pageSize);
		
		System.out.println(itemList.size());
		
		for(GroupItem i :itemList){
			System.out.println(i.getName());
		}
		
		JSONArray jsonArray = new JSONArray(itemList);
		
		String result = jsonArray.toString();
		
		try{
			
			this.response.getWriter().write(result);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void setServletResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub
		this.response = response;
	}

	public void setServletRequest(HttpServletRequest request) {
		// TODO Auto-generated method stub
		this.request = request;
	}

	public GroupItemService getGroupItemService() {
		return groupItemService;
	}

	public void setGroupItemService(GroupItemService groupItemService) {
		this.groupItemService = groupItemService;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageNow() {
		return pageNow;
	}

	public void setPageNow(int pageNow) {
		this.pageNow = pageNow;
	}
	
}
